import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-26
 * Time: 15:44
 */
public class Dome_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int num = in.nextInt();
            int[] prices = new int[num];
            int max_money = 0;
            int min=Integer.MAX_VALUE;
            for (int i = 0; i < num; i++) {
                prices[i] = in.nextInt();
                if (min>prices[i]){
                    min=prices[i];
                }
                if (max_money<prices[i]-min){
                    max_money=prices[i]-min;
                }
            }
            System.out.println(max_money);
        }
    }
}
